package liumengbaio.lolzhangyoubao.Activity.utils;


import android.content.Context;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.SkillsInfo;

/**
 * 召唤师技能的获取方法
 * Created by lanouhn on 16/9/1.
 */
public class SkillsUtils {

//    public static List<SummonerSkillsInfo> getSummonerSkillsInfoList(Context mContext) {
//        List<SummonerSkillsInfo> lssi = new ArrayList<>();
//        for (int i = 0; i < lssi.size(); i++) {
//            SummonerSkillsInfo ssi = getSummonerSkillsInfoList(mContext);
//            lssi.add(ssi);
//        }
//        return lssi;
//    }

    /**
     * 获取对应ID的召唤师技能信息
     *
     * @param mContext
     * @return
     */
    public static List<SkillsInfo> getSkillsInfo(Context mContext) {

        List<SkillsInfo> lssi = new ArrayList<>();
        try {
            InputStream is = mContext.getAssets().open("hero/heroskills.json");
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            is.close();

            String text = new String(buffer, "UTF-8");
            JSONObject mObject = new JSONObject(text);
            JSONArray array = mObject.getJSONArray("data");

            for (int i = 0; i < array.length(); i++) {
                SkillsInfo ssi = new SkillsInfo();
                JSONObject jsonObject = array.getJSONObject(i);
                ssi.setPic_url(jsonObject.getString("pic_url"));
                ssi.setName(jsonObject.getString("name"));
                ssi.setId(jsonObject.getString("id"));
                ssi.setRole_id(jsonObject.getString("role_id"));
                ssi.setVideo_path(jsonObject.getString("video_path"));
                ssi.setKey(jsonObject.getString("key"));
                ssi.setPassive(jsonObject.getString("passive"));
                ssi.setCold(jsonObject.getString("cold"));
                ssi.setBlood(jsonObject.getString("blood"));
                ssi.setEnergy(jsonObject.getString("energy"));
                ssi.setMana(jsonObject.getString("mana"));
                ssi.setDesc(jsonObject.getString("desc"));
                lssi.add(ssi);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lssi;
    }

}
